$(function() {
	admin.userDraw.init();
});
Namespace('admin.userDraw', {
	init : function() {
		easyui.util.initDatagrid('#datagrid', {
			onDblClickRow : function() {
			}
		});
	},
	query : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	detail:function(id,userId,drawItemId) {
		if (id != null) {
			top.addTab(id,'详情', contextPath+'/user/draw/detail/'+id+'/'+userId+'/'+drawItemId);
		}
	},
	toAdd:function() {
		top.addTab("1",'添加', contextPath+'/user/draw/toAdd');
	},
	toUpdate:function(id) {
		if (id != null) {
			top.addTab(id,'编辑', contextPath+'/user/draw/toUpdate?id=' + id);
		}
	},
	update: function () {
	 	if(!$('#data-form').form('validate')) return;
        var data=$('#data-form').form('jsonObject');
        
        var url = contextPath + '/user/draw/update';
        $('#datagrid').datagrid('loading');
		$.post(url, data, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('编辑成功');
				top.addTab("1",'用户抽奖列表', contextPath+'/user/draw/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	add: function () {
		 	if(!$('#data-form').form('validate')) return;
	        var data=$('#data-form').form('jsonObject');
            var url = contextPath + '/user/draw/create';
			$.post(url, data, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('创建成功');
					top.addTab("",'用户抽奖列表', contextPath+'/user/draw/list');
				} else {
					top.showInfo(result.msg);
				}
			});
	},
	unclaimed:function(id) {
		var url = contextPath + '/user/draw/unclaimed';
        $('#datagrid').datagrid('loading');
		$.post(url, {id:id}, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('设置未领取成功');
				top.addTab("1",'用户抽奖列表', contextPath+'/user/draw/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	receive:function(id) {
		var url = contextPath + '/user/draw/receive';
        $('#datagrid').datagrid('loading');
		$.post(url, {id:id}, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('设置已领取成功');
				top.addTab("1",'用户抽奖列表', contextPath+'/user/draw/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
});